package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.ListQuadrat;
import com.fsnbigdata.domain.QListQuadrat;
import com.fsnbigdata.domain.Vegetation;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = ListQuadratRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = ListQuadratRepositoryCustom.class)
@Transactional(readOnly = true)
public class ListQuadratRepositoryImpl extends QueryDslRepositorySupportExt<ListQuadrat> implements ListQuadratRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    ListQuadratRepositoryImpl() {
        super(ListQuadrat.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LOCATION = "location";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SHRUB_LAYER_COVERAGE = "shrubLayerCoverage";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String FIELD_LAYER_COVERAGE = "fieldLayerCoverage";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ALTITUDE = "altitude";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String GRADIENT = "gradient";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String TREE_LAYER_COVERAGE = "treeLayerCoverage";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SHRUB_LAYER_AREA = "shrubLayerArea";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String QUADRAT_YEAR = "quadratYear";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String TREE_LAYER_AREA = "treeLayerArea";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String FIELD_LAYER_AREA = "fieldLayerArea";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String COORDINATE = "coordinate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String EXPOSURE = "exposure";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String VEGETATION = "vegetation";

    /**
     * TODO Auto-generated method documentation
     *
     * @param vegetation
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<ListQuadrat> findByVegetation(Vegetation vegetation, GlobalSearch globalSearch, Pageable pageable) {
        QListQuadrat listQuadrat = QListQuadrat.listQuadrat;
        JPQLQuery<ListQuadrat> query = from(listQuadrat);
        Assert.notNull(vegetation, "vegetation is required");
        query.where(listQuadrat.vegetation.eq(vegetation));
        Path<?>[] paths = new Path<?>[] { listQuadrat.vegetation, listQuadrat.quadratYear, listQuadrat.location, listQuadrat.coordinate, listQuadrat.altitude, listQuadrat.gradient, listQuadrat.exposure, listQuadrat.treeLayerArea, listQuadrat.treeLayerCoverage, listQuadrat.shrubLayerArea, listQuadrat.shrubLayerCoverage, listQuadrat.fieldLayerArea, listQuadrat.fieldLayerCoverage };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(VEGETATION, listQuadrat.vegetation).map(QUADRAT_YEAR, listQuadrat.quadratYear).map(LOCATION, listQuadrat.location).map(COORDINATE, listQuadrat.coordinate).map(ALTITUDE, listQuadrat.altitude).map(GRADIENT, listQuadrat.gradient).map(EXPOSURE, listQuadrat.exposure).map(TREE_LAYER_AREA, listQuadrat.treeLayerArea).map(TREE_LAYER_COVERAGE, listQuadrat.treeLayerCoverage).map(SHRUB_LAYER_AREA, listQuadrat.shrubLayerArea).map(SHRUB_LAYER_COVERAGE, listQuadrat.shrubLayerCoverage).map(FIELD_LAYER_AREA, listQuadrat.fieldLayerArea).map(FIELD_LAYER_COVERAGE, listQuadrat.fieldLayerCoverage);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, listQuadrat);
    }
}
